<?php
/*
 * @Descripttion:
 * @version:
 * @Author: ewgof
 * @Date: 2020-03-26 15:49:34
 * @LastEditors: ewgof
 * @LastEditTime: 2020-10-08 06:50:29
 */
namespace app\http\controller\admin;

use app\common\model\NewAddModel;

class Index extends Base
{
    public function index()
    {
        echo 'PicBed Admin Index';
    }


    // 后台首页新增数据统计
    // type: 1 => users, 2 => user_img, 3 => guest_img
    public function newlyAdd()
    {
        $time_0 = mktime(0, 0, 0, date('m'), date('d')-date('w'), date('Y'));
        $time_6 =  mktime(23, 59, 59, date('m'), date('d')-date('w')+6, date('Y'));

        $newly_add_user_info = [
            'number' => 0,
            'type' => 1,
        ];
        $newly_add_user_img_info = [
            'number' => 0,
            'type' => 2,
        ];
        $newly_add_guest_img_info = [
            'number' => 0,
            'type' => 3,
        ];
        $newly_add_user_number = $this->db->count('users', ['created_at[<>]' => [$time_0, $time_6]]);
        if (!empty($newly_add_user_number)) {
            $newly_add_user_info['number'] = $newly_add_user_number;
        }
        $newly_add_user_img_number = $this->db->count('user_imgs', ['created_at[<>]' => [$time_0, $time_6]]);
        if (!empty($newly_add_user_img_number)) {
            $newly_add_user_img_info['number'] = $newly_add_user_img_number;
        }
        $newly_add_guest_img_number = $this->db->count('guest_imgs', ['created_at[<>]' => [$time_0, $time_6]]);
        if (!empty($newly_add_guest_img_number)) {
            $newly_add_guest_img_info['number'] = $newly_add_guest_img_number;
        }
        $info = [
            'newly_add_user_info' => $newly_add_user_info,
            'newly_add_user_img_info' => $newly_add_user_img_info,
            'newly_add_guest_img_info' => $newly_add_guest_img_info,
        ];
        return api_json_return(0, '', $info);
    }
}
